package com.xi.springboot.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xi.springboot.annotation.SysLog;
import com.xi.springboot.entity.User;
import com.xi.springboot.mapper.UserMapper;
import com.xi.springboot.service.UserService;
import com.xi.springboot.utils.UrlUtils;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: xjs
 * @Date: 2022/11/19/10:58
 * @Description:
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @SysLog("登录校验")
    @Override
    public User login(String userName, String password) {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        String pwd = DigestUtils.md5Hex(password);
        wrapper.eq(User::getUsername,userName).eq(User::getPassword,pwd);
         User user = userMapper.selectOne(wrapper);
        System.out.println("查询"+userMapper.selectOne(wrapper));
        return user;
    }


    @SysLog("用户注册")
    @Override
    public Boolean insertUser(String userName, String password) {
        User user = new User();
        user.setUsername(userName);
        String pwd = DigestUtils.md5Hex(password);
        user.setPassword(pwd);
        user.setSeparate(UrlUtils.getUrl());
        return userMapper.insert(user)>0;
    }

}
